import { Module } from "vuex";
// 该泛型需结合两个参数
import ISystemState from "./type";
import { IRootState } from "@/store/types";
import {
  postEmployeeData,
  getPageListData,
  deletePageDataById,
  uploadAvatar,
  editPagedata
} from "@/service/main/system/system";
const systemModule: Module<ISystemState, IRootState> = {
  // 提供一个作用域
  namespaced: true,
  state() {
    return {
      userList: [],
      userCount: 0
    };
  },
  actions: {
    async getemployeeCountAction({ commit }, payload: any) {
      const result = await getPageListData(payload);
      const { data, total } = result.data;
      if (total == 200) {
        commit("USERLIST", data);
      }
    },
    // async postemployeedata({ commit }, payload: any) {
    //   console.log("post", payload);
    //   const employeedata = await postEmployeeData(payload);
    // },
    // 删除列表中的某一列
    async deletePageDateAction({ dispatch }, payload: any) {
      const deletePageDate = await deletePageDataById(payload);
      // 重新发起网络请求
      dispatch("getemployeeCountAction", {
        queryinfo: {
          start: 1,
          end: 5
        }
      });
    },
    // 编辑列表中的某一列
    async editPageDataAction({ dispatch }, payload) {
      console.log(payload);
      // const { nickname, phone, id, gender } = payload;
      await editPagedata(payload);
      // 重新发起数据请求
      dispatch("getemployeeCountAction", {
        queryinfo: {
          start: 1,
          end: 5
        }
      });
    },
    async uploadAvatarReq({ commit }, payload: any) {
      console.log("post", payload);
      const uploadData = await uploadAvatar(payload);
      console.log(uploadData);
    }
  },
  mutations: {
    USERLIST(state, data) {
      state.userList = data;
    }
  },
  getters: {
    userlist(state) {
      return state.userList;
    }
  }
};
export default systemModule;
